package com.apes.framework.rop.session.index;

import com.apes.framework.plugin.cache.Cache;
import com.apes.framework.rop.securityManager.SampleSessionManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 功能：
 *
 * @author xul
 * @create 2020-01-17 9:31
 */
@Component
public class SampleSessionIndexManager implements SessionIndexManager<Integer, List<SessionIndexItem>> {
    protected final Logger logger = LogManager.getLogger(SampleSessionManager.class);

    private final String CONST_DEFAULT_CACHE_INDEX_NAME = "sessionIndexCache";

    @Autowired
    private Cache cache;

    @Override
    public void add(Integer userId, List<SessionIndexItem> sessionIndexItems) {
        cache.put(CONST_DEFAULT_CACHE_INDEX_NAME, userId, sessionIndexItems);
    }

    @Override
    public List<SessionIndexItem> get(Integer userId) {
        return (List<SessionIndexItem>) cache.get(CONST_DEFAULT_CACHE_INDEX_NAME, userId);
    }

    @Override
    public void remove(Integer userId) {
        cache.remove(CONST_DEFAULT_CACHE_INDEX_NAME, userId);
    }
}
